package co.yixiang.huiMin.controller;


import co.yixiang.annotation.AnonymousAccess;
import co.yixiang.huiMin.dao.MachinistQueryCriteria;
import co.yixiang.huiMin.entity.DriveTypes;
import co.yixiang.huiMin.entity.Machinist;
import co.yixiang.huiMin.service.DriveTypesService;
import co.yixiang.modules.shop.domain.DriverInfo;
import co.yixiang.modules.shop.service.DriverInfoService;
import co.yixiang.modules.shop.service.dto.YxStoreCategoryDTO;
import co.yixiang.modules.shop.service.dto.YxUserDTO;
import co.yixiang.utils.PageUtil;
import co.yixiang.utils.QueryHelp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 司机类型 前端控制器
 * </p>
 *
 * @author Author
 * @since 2020-07-31
 */
@RestController
@Api(tags = "司机分类")
@RequestMapping("/driveTypes")
public class DriveTypesController {

    @Resource
    private DriveTypesService driveTypesService;

    /**
     * 查询司机分类
     * @return
     */
    @AnonymousAccess
    @ApiOperation("查询司机分类")
    @GetMapping("/selectDriveTypesAll")
    public ResponseEntity<Object> selectDriveTypesAll() {
        List<DriveTypes> list=driveTypesService.selectDriveTypesAll();

        HashMap<String, Object> resultMap = new HashMap<>();
        resultMap.put("code",200);
        resultMap.put("message", list);
        return new ResponseEntity<>(resultMap, HttpStatus.OK);

    }


    /**
     *添加司机分类
     * @return
     */
    @AnonymousAccess
    @ApiOperation("添加司机分类")
    @PostMapping("/insetrDriveTypes")
    public ResponseEntity<Object> insetrDriveTypes(@RequestBody DriveTypes driveTypes){
        int count=driveTypesService.insetrDriveTypes(driveTypes);
        HashMap<String, Object> resultMap = new HashMap<>();
        if(count>0){
            resultMap.put("code",200);
            return new ResponseEntity<>(resultMap, HttpStatus.OK);
        }
        resultMap.put("code",300);
        return new ResponseEntity<>(resultMap, HttpStatus.OK);
    }

    /**
     * 根据id查询司机分类详情
     * @return
     */
    @AnonymousAccess
    @ApiOperation("根据id查询司机分类详情")
    @GetMapping("/selectDriveTypesById")
    public ResponseEntity<Object> selectDriveTypesById(String id) {
        HashMap<String, Object> resultMap = new HashMap<>();
        resultMap.put("code",200);
        resultMap.put("message", driveTypesService.selectDriveTypesById(id));
        return new ResponseEntity<>(resultMap, HttpStatus.OK);

    }

    /**
     *修改司机分类
     * @return
     */
    @AnonymousAccess
    @ApiOperation("修改司机分类")
    @PostMapping("/updateDriveTypes")
    public ResponseEntity<Object> updateDriveTypes(@RequestBody DriveTypes driveTypes){
        int count=driveTypesService.updateDriveTypes(driveTypes);
        HashMap<String, Object> resultMap = new HashMap<>();
        if(count>0){
            resultMap.put("code",200);
            return new ResponseEntity<>(resultMap, HttpStatus.OK);
        }
        resultMap.put("code",300);
        return new ResponseEntity<>(resultMap, HttpStatus.OK);
    }
    /**
     *删除司机分类
     * @return
     */
    @AnonymousAccess
    @ApiOperation("删除司机分类")
    @PostMapping("/deleteDriveTypes")
    public ResponseEntity<Object> deleteDriveTypes(@RequestBody DriveTypes driveTypes){
        driveTypes.setDelFlag(1);
        int count=driveTypesService.updateDriveTypes(driveTypes);
        HashMap<String, Object> resultMap = new HashMap<>();
        if(count>0){
            resultMap.put("code",200);
            return new ResponseEntity<>(resultMap, HttpStatus.OK);
        }
        resultMap.put("code",300);
        return new ResponseEntity<>(resultMap, HttpStatus.OK);
    }
}

